/*
 * ipdly_eth.h
 *
 *  Created on: 2018年9月26日
 *  Author: Degang.Wu (windragon@126.com)
 *  Desc:
 */

#ifndef ENC_ETH_H_
#define ENC_ETH_H_

#include <linux/if_packet.h>

#define BUFFER_MAX 2048
#define PCKT_LEN 8492

#define ETH_HDRLEN 14      // Ethernet header length
#define IP4_HDRLEN 20      // IPv4 header length
#define ARP_HDRLEN 28      // ARP header length
#define ARPOP_REQUEST 1    // Taken from <linux/if_arp.h>
#define ARPOP_RESPONSE 2

#pragma pack (1)
//ethernet head 14 bytes
typedef struct ether_
{
	char dmac[6];
	char smac[6];
	unsigned short eth_type;
}ether;

// arp head
typedef struct _arp_hdr {
	unsigned short 	htype;
	unsigned short 	ptype;
	unsigned char 		hlen;
	unsigned char 		plen;
	unsigned short 	opcode;
	unsigned char 		sender_mac[6];
	unsigned int	 	sender_ip;
	unsigned char 		target_mac[6];
	unsigned int	 	target_ip;
}arp_hdr;

//ip head 20 bytes
typedef struct ipheader_ {
	unsigned char      iplv;//iph_ihl:5, iph_ver:4;
	unsigned char      iph_tos;
	unsigned short int iph_len;
	unsigned short int iph_ident;
	// unsigned uint8_t      iph_flag;
	unsigned short int iph_offset;//16bit include flag and offset
	unsigned char      iph_ttl;
	unsigned char      iph_protocol;
	unsigned short int iph_chksum;
	unsigned int       iph_sourceip;
	unsigned int       iph_destip;
}ipheader;

//udp head 8 bytes
typedef struct udpheader_ {
	unsigned short int udph_srcport;
	unsigned short int udph_destport;
	unsigned short int udph_len;
	unsigned short int udph_chksum;
}udpheader;

typedef struct _packethdr
{
	ether			ethhdr;
	ipheader		iphdr;
	udpheader		udphdr;
	char			buf[2048];		//udp payload buffer
}st_packethdr;


typedef struct _arp_packet
{
	ether			ethhdr;
	arp_hdr			arphdr;
}st_arp_pkt;

#pragma pack ()


#endif /* ENC_ETH_H_ */
